import lodash from 'lodash';
import * as dao from '../data/medicalRecord';
import log from '../log';

export function getClassAndSeg(isactive) {
    return dao.getClassAndSeg(isactive).then(res => {
        log.info('getClassAndSeg result----', JSON.stringify(res.toJSON()));
        return res ? res.toJSON() : [];
    }).catch(err => {
        log.error('getRecordDictionary is err', err.message || err);
        return err.message || err;
    });
}
export function getElementBySegCode(segcode, isactive) {
    return dao.getElementBySegCode(segcode, isactive).then(res => {
        log.info('getElementBySegCode result ----', JSON.stringify(res.toJSON()));
        const elements = res ? res.toJSON() : [];
        const result = [];
        if (elements.length > 0) {
            elements[0].elements.forEach((item) => {
                const _ = {
                    code: item.code,
                    name: item.name,
                    type: item.type,
                    segcode: elements[0].code,
                    rules: [{
                        require: item.isextract,
                        message: '必填项'
                    }]
                };
                result.push(_);
            });
        }
        return result;
    }).catch(err => {
        log.error('getElementBySegCode is err', err.message || err);
        return err.message || err;
    });
}
export function getValuesByEleCode(elecode, isactive) {
    return dao.getValuesByEleCode(elecode, isactive)
        .then(res => {
            log.info('getValuesByEleCode result ----', JSON.stringify(res.toJSON()));
            const result = res ? res : [];
            return result;
        }).catch(err => {
            log.error('getValuesByEleCode is err', err.message || err);
            return err.message || err;
        });
}
